import {
  PLATFORMS_DATAS,
  DEVUCEINFO_DATAS,
  PAY_DATAS
} from "../../Action/nativeDatas/nativeDatas";
import {isServer} from "@tools/utils";
import objectAssign from "object-assign";

//获取设备信息
const _deviceInfoData = {
  deviceInfo: {},
  iphonex: ""
};


const deviceInfoData = isServer ? _deviceInfoData : window.sessionStorage.getItem("deviceInfoDatas")
  ? JSON.parse(window.sessionStorage.getItem("deviceInfoDatas"))
  : _deviceInfoData;
const getDeviceInfoDatas = (state = deviceInfoData, action = {}) => {
  switch (action.type) {
    case DEVUCEINFO_DATAS:
      window?.sessionStorage?.setItem(
        "deviceInfoDatas",
        JSON.stringify(objectAssign({}, state, action.options))
      );
      return objectAssign({}, state, action.options);
    default:
      return state;
  }
};
//获取sdk的数据
const _getAppPlatformsData = {
  sdkVersionCode: "1.0.0", // sdk版本号
  mutDic: {
    phoneX: false
  },
  /**sdk初始化部分 */
  pageType: "-1", // 需要打开页面的类型
  merchantId: "", // 商户id
  userId: "", // 用户id
  data: "", // 签名数据
  sign: "", // 加签后的数据
  mobile: "", // 手机号
  extendJson: "", // 扩展数据

  unionid: "",
  channelCode: "", //渠道号
  appVersion: "", //app版本号
  deviceInfo: "", //设备品牌加型号
  deviceVersion: "", //操作系统及版本
  plateform: "", //平台Android
  deviceId: "", //设备唯一标识
  appChannel: "", //渠道

  longitude: "",
  latitude: "",
  lnid: "", //产品编码
  applyNo: "", //申请编号
  authHeaderStr: "{}",
  payCouponList: [],
  isFromPayMoney: false // 是否来自收银台
};

const getAppPlatformsData = isServer ? _getAppPlatformsData : sessionStorage.getItem("getAppPlatformsDatas") ? JSON.parse(sessionStorage.getItem("getAppPlatformsDatas"))
  : _getAppPlatformsData

const getAppPlatformsDatas = (state = getAppPlatformsData, action = {}) => {
  switch (action.type) {
    case PLATFORMS_DATAS:
      window.sessionStorage.setItem(
        "getAppPlatformsDatas",
        JSON.stringify(objectAssign({}, state, action.options))
      );
      return objectAssign({}, state, action.options);
    default:
      return state;
  }
};

//获取支付结果页面的数据
const _getPayData = {
  goodsAmount: "0.00", //商品金额
  couponAmount: "0.00", //优惠券金额
  amount: "0.00", //支付金额
  storeName: "", //商户名称
  cashBackAmount: "0.00", //红包金额
  randomAmount: "0.00", //随机立减
  payDiscountAmount: "0.00" //优惠活动
};
const getPayData = isServer ? _getPayData : window.sessionStorage.getItem("getPayDatas")
  ? JSON.parse(window.sessionStorage.getItem("getPayDatas"))
  : _getPayData;
const getPayDatas = (state = getPayData, action = {}) => {
  switch (action.type) {
    case PAY_DATAS:
      window?.sessionStorage?.setItem(
        "getPayDatas",
        JSON.stringify(objectAssign({}, state, action.options))
      );
      return objectAssign({}, state, action.options);
    default:
      return state;
  }
};

export {getDeviceInfoDatas, getAppPlatformsDatas, getPayDatas};
